//
//  HotCityTableViewCell.m
//  MemoryTravel
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "HotCityTableViewCell.h"

@implementation HotCityTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews{
    self.contentView.backgroundColor = [UIColor colorWithRed:65 / 255.0 green:176 / 255.0 blue:194 / 255.0 alpha:1.0];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //每个section内置设置的大小
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
    //设置每个item(cell)的大小
    flowLayout.itemSize = CGSizeMake((Width - 60) / 3.0, 30);
    //设置最小行间距
    flowLayout.minimumLineSpacing = 15;
    //设置最小列间距
    flowLayout.minimumInteritemSpacing = 15;
    
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Width, 105) collectionViewLayout:flowLayout];
    self.myCollectionView.backgroundColor = [UIColor colorWithRed:65 / 255.0 green:176 / 255.0 blue:194 / 255.0 alpha:1.0];
    self.myCollectionView.dataSource = self;
    self.myCollectionView.delegate = self;
    [self.contentView addSubview:self.myCollectionView];
    
    [self.myCollectionView registerClass:[CustonCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.myArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    
    CustonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.city = [self.myArray objectAtIndex:indexPath.row];
    cell.customCollectionViewCellDelegate = self;
    
    return cell;
}

- (void)addressPass:(NSString *)cityName{
    [self.hotCityTableViewCellDelegate addressPass_:cityName];
}

- (void)setMyArray:(NSMutableArray *)myArray{
    if (_myArray != myArray) {
        _myArray = myArray;
    }
    [self.myCollectionView reloadData];
    NSLog(@"几次几次几次？？？");
}

@end
